package org.usfirst.team3132.util;

/**
 *
 * @author Matt
 */
public class AverageQueue extends Queue {
    private int size = 0;
    private double sum = 0.0;
    private int maxElements;
    
    public AverageQueue (int maxElements) {
        this.maxElements = maxElements;
    }
    
    public void push (double number) {
        super.push(number);
        size++;
        sum += number;
        if (size > maxElements) {
            sum -= super.pop().doubleValue();
            size--;
        }
    }
    
    public double getAvg () {
        if (size == 0) {
            return 0;
        }
        return sum / size;
    }
    
    public Double pop() {
        throw new RuntimeException("User cannot pop manually, will automatically pop");
    }
}
